package com.skyline2yc.databus.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.skyline2yc.databus.entity.DataMarket;
import com.skyline2yc.databus.entity.DataSource;
import com.skyline2yc.databus.mapper.DataSourceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
@Transactional
public class DataSourceService {

    @Autowired
    private DataSourceMapper dataSourceMapper;


    /**
     * 获取所有数据源的名称
     */
    public List<String> selectAll() {
        LambdaQueryWrapper<DataSource> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.select(DataSource::getBeanName);
        List<String> result = dataSourceMapper.selectObjs(lambdaQueryWrapper).stream()
                .map(o -> (String) o)
                .collect(Collectors.toList());

        return result;

    }

    /**
     * 根据数据源名称获取所有数据库实例名
     */
    public List<String> queryByName(String beanName) {
        List<String> serverNames = dataSourceMapper.findServerName(beanName);
        return serverNames;
    }


}
